# -*- coding: utf-8 -*-
from django.contrib.auth.models import User
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.models import ContentType
from django.db import models

from assets.models import Asset

class Bundle(models.Model):
  name = models.CharField(max_length=256, db_index=True)

  content_type = models.ForeignKey(ContentType)
  object_id = models.CharField(max_length=40, db_index=True)
  content_object = generic.GenericForeignKey()

  assets = models.ManyToManyField(Asset)
  
  created = models.DateTimeField(db_index=True, auto_now_add=True)
  modified = models.DateTimeField(db_index=True, auto_now=True)

  def __unicode__(self):
    return u"%s tagged %s - %s: %s" % (self.user, self.content_type, self.content_type, self.tag)

  class Meta:
    unique_together = (('name', 'content_type', 'object_id'),)
    ordering = ('-created',)
